<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <button id="btn">转换数据</button>
  <script>
    var arr = {
      tiku: '测试题库',
      leixing: '单选',
      daan: 'A~B',
      xuanxiang: '这是第一个选项~这是第二个选项~这是第三个选项~这是第四个选项~这是第五个选项'
    }
    console.log(arr)
    let btn = document.getElementById('btn')
    btn.onclick = function () {
      let daanXin = arr.daan.split('~')
      // console.log(daanXin)
      let xuanxiangXin = arr.xuanxiang.split('~')
      // console.log(xuanxiangXin)
      let obj = {}
      obj.tiku = arr.tiku
      obj.leixing = arr.leixing
      obj.option = []
      for (let i = 0; i < xuanxiangXin.length; i++) {
        let zimu = String.fromCharCode(65 + i)
        let xxiang = xuanxiangXin[i]
        let crr = {}
        // console.log(zimu)
        // console.log(xxiang)
        crr.code = zimu
        crr.xxiang = xxiang
        // console.log(crr)
        // obj.option = { ...obj.option, ...crr }
        // obj.option.push(Object.assign(crr))
        obj.option.push(crr)
      }
      // obj.option.push(crr)
      // console.log(obj.option)
      daanXin.map(item => {
        obj.option.map((val, index) => {
          if (item === val.code) {
            val.isRight = true
          } else if (val.isRight === true) {
            val.isRight = true
          } else {
            val.isRight = false
          }
        })
      })
      // console.log(obj.option)
      console.log(obj)
    }
  </script>
</body>

</html>